package cn.yzx.pethome.system.sdt.service.impl;

import cn.yzx.pethome.system.sdt.domain.SystemDictionaryDetail;
import cn.yzx.pethome.system.sdt.domain.SystemDictionaryType;
import cn.yzx.pethome.system.sdt.mapper.SystemDictionaryDetailMapper;
import cn.yzx.pethome.system.sdt.mapper.SystemDictionaryTypeMapper;
import cn.yzx.pethome.base.service.impl.BaseServiceImpl;
import cn.yzx.pethome.system.sdt.service.ISystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class SystemDictionaryTypeServiceImpl extends BaseServiceImpl<SystemDictionaryType> implements ISystemDictionaryTypeService {
    @Autowired
    private SystemDictionaryTypeMapper systemDictionaryTypeMapper;
    @Autowired
    private SystemDictionaryDetailMapper systemDictionaryDetailMapper;

    @Override
    @Transactional
    public void delete(Long id) {
        List<SystemDictionaryDetail> list = systemDictionaryDetailMapper.selectById(id);
        if (list.size() == 0){
            systemDictionaryTypeMapper.delete(id);
        }else {
            throw new RuntimeException("请将字典明细删除后执行");
        }
    }
}